package com.xmut.rc.service.impl;

import com.xmut.rc.entity.RolePermission;
import com.xmut.rc.mapper.RolePermissionMapper;
import com.xmut.rc.service.RolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @description: 角色权限接口实现
 * @author: XS
 * @date: 2022/5/23
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {
    @Resource
    private RolePermissionMapper rolePermissionMapper;

    @Override
    @Transactional
    public boolean updateUserRole(String roleId, String permissionIds) {
        //删除当前用户权限
        rolePermissionMapper.deleteRolePermission(roleId);
        String[] ids = permissionIds.split(",");
        for (String permissionId : ids) {
            RolePermission rolePermission=new RolePermission();
            rolePermission.setPermissionId(permissionId);
            rolePermission.setRoleId(roleId);
            rolePermissionMapper.insert(rolePermission);
        }
        return true;
    }
}
